package com.inkyi.assistant.app.todolist;

import com.formdev.flatlaf.FlatLightLaf;
import com.inkyi.assistant.app.todolist.event.TodoEvent;
import com.inkyi.assistant.app.todolist.event.TodoEventListener;
import com.inkyi.assistant.app.todolist.left.TodoLeftPanel;
import com.inkyi.assistant.app.todolist.right.TodoRightPanel;
import com.inkyi.assistant.core.AssistantCoreApplication;

import javax.swing.*;

public class TodoListMain extends JSplitPane {

    private TodoLeftPanel classifyPanel;

    private TodoRightPanel todoPanel;

    public TodoListMain() {
        initComponents();
    }

    private void initComponents() {
        classifyPanel = new TodoLeftPanel();
        todoPanel = new TodoRightPanel();
        this.setDividerLocation(200);
        this.setLeftComponent(classifyPanel);
        this.setRightComponent(todoPanel);
        TodoContext.setTodoListMain(this);
        TodoContext.getEventWrap().addActionListener(new TodoEventListener());
        TodoContext.getEventWrap().fireActionEvent(TodoEvent.of(this, TodoEvent.TYPE_LOAD_INIT_DATA));
    }


    public static void main(String[] args) {

        AssistantCoreApplication.main(args);

        try {
            UIManager.setLookAndFeel(new FlatLightLaf());
        } catch (Exception ex) {
            System.err.println("Failed to initialize LaF");
        }

        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(1000, 700);
        frame.setLocationRelativeTo(null);

        TodoListMain todoListMain = new TodoListMain();

        frame.add(todoListMain);
        frame.setVisible(true);

    }
}
